#include <iostream>
#include <string>
using namespace std;
const int N = 1000;
// 准考证号a 试机座位号b 考试座位号c 查询试机的号码
string a[N+5];
int b[N+5];
int b_hash[N+5];
int c[N+5];
int d[N+5];

int main(){
    int n,m;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i] >> c[i];
        b_hash[b[i]] = i;
    }
    cin >> m;
    for(int i = 0; i < m; ++i){
        cin >> d[i];
        int index = b_hash[d[i]];
        cout << a[index] << " " << c[index] << endl; ;   
    }
    return 0;
}